﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace cubeworld.ScreenManager
{
    class Button
    {
        String text;
        Screen screen;
        Vector2 position;

        bool quit;

        Color c = Color.White;
        static Point mousePoint;

        public Button(String Text, Screen screen, Vector2 position, bool quit = false)
        {
            this.text = Text;
            this.screen = screen;
            this.position = position;
            this.quit = quit;
        }

        public void Render(SpriteBatch spriteBatch)
        {
            bool hover = false;

            mousePoint = new Point(Mouse.GetState().X, Mouse.GetState().Y);
            if (new Rectangle((int)position.X, (int)position.Y, (int)Data.buttonNormal.Width,
                (int)Data.buttonNormal.Height)
                .Contains(mousePoint))
            {
                //Zeichne Hover Button
                spriteBatch.Draw(Data.buttonHover, 
                    new Rectangle((int)position.X, (int)position.Y, (int)Data.buttonNormal.Width, (int)Data.buttonNormal.Height), Color.White);
                hover = true;
            }
            else
            {
                //Zeichne Normal Button
                spriteBatch.Draw(Data.buttonNormal, 
                    new Rectangle((int)position.X, (int)position.Y, (int)Data.buttonNormal.Width, (int)Data.buttonNormal.Height), Color.White);
                hover = false;
            }

            Vector2 textV = Data.debugFont.MeasureString(text);
            Vector2 textPos = new Vector2((Data.buttonNormal.Width / 2) - (textV.X / 2) + position.X, (Data.buttonNormal.Height / 2) - (textV.Y / 2) + position.Y);
            spriteBatch.DrawString(Data.debugFont, text, textPos, Color.White);

            if (hover == true && Mouse.GetState().LeftButton == ButtonState.Pressed && quit == false)
                Data.SetScreen(screen);
            else if (hover == true && Mouse.GetState().LeftButton == ButtonState.Pressed && quit == true)
                MainGame.isClosed = true;

        }
    }
}
